//
//  WBNaviViewController.swift
//  Swift_weiboDemo
//
//  Created by toro宇 on 2017/5/9.
//  Copyright © 2017年 toro宇. All rights reserved.
//

import UIKit

class WBNaviViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 隐藏系统的导航栏
        navigationBar.isHidden = true
    }
    // 重写 push 方法，所有的push 动作都会调用此方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        // 如果不是栈低控制器才需要隐藏，跟控制器不需要处理
        if viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            var title = "返回"
            if let vc = viewController as? WBBaseViewController {
                
                if viewControllers.count == 1 {
                    title = viewControllers.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popParentVC) ,backImage: true)
                
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    func popParentVC(){
        popViewController(animated: true)
    }

}
